import App from './App'

// 引入store，vuex
import store from './vuex/store.js'

// 配置网络请求工具
import { $http } from '@escook/request-miniprogram'

//引入uView
import uView from '@/uni_modules/uview-ui'
Vue.use(uView)

uni.$http = $http

// 配置网络请求根路径
$http.baseUrl = 'https://api-hmugo-web.itheima.net'

// 请求拦截器
$http.beforeRequest = function (options) {
  uni.showLoading({
    title: '数据加载中...',
  });
  if(options.url.indexOf(/my/) !== -1 && store.state.m_user.token !== ''){
	options.header = {
		Authorization : store.state.m_user.token
	}
  };
}

// 响应拦截器
$http.afterRequest = function () {
  uni.hideLoading()
}

//配置消息展示函数
 uni.$showToast = function(text = "数据加载失败"){
	 uni.showToast({
	 	title: text,
		duration: 1500,
		icon: "none"
	 })
 }

// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'

const app = new Vue({
    ...App,
	store
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif